<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp" %>
<html>
<head>
    <title>用户管理</title>
    <meta name="decorator" content="ani"/>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#inputForm").find("select").each(function (k, y) {
                if ($(this).attr("data-value") != '') {
                    $(this).val($(this).attr("data-value"));
                }
                if ($(this).attr("data-tableName") != undefined && $(this).attr("data-tableName") != '') {//判断是否是下拉关联select
                    jp.initSelectLD($("#" + y.id), "${ctx}/getSelectList");
                }

            });
        })

        function save() {
            var isValidate = jp.validateForm('#inputForm');//校验表单
            if (!isValidate) {
                return false;
            } else {
                jp.loading();
                jp.post("${ctx}/sys/user/save", $('#inputForm').serialize(), function (data) {
                    if (data.success) {
                        jp.getParent().refresh();
                        var dialogIndex = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                        parent.layer.close(dialogIndex);
                        jp.success(data.msg)

                    } else {
                        jp.error(data.msg);
                    }
                })
            }

        }

        $(document).ready(function () {
            $("#no").focus();
            $("#inputForm").validate({
                rules: {
                    loginName: {remote: "${ctx}/sys/user/checkLoginName?oldLoginName=" + encodeURIComponent('${user.loginName}')}
                },
                messages: {
                    loginName: {remote: "用户登录名已存在"},
                    confirmNewPassword: {equalTo: "输入与上面相同的密码"}
                }
            });

        });


    </script>
</head>
<body class="bg-white">
<form:form id="inputForm" modelAttribute="user" method="post" class="form-horizontal">
    <form:hidden path="id"/>
        <fieldset>
            <legend><i style="padding: 0px 5px 0px 5px" class="fa fa-hand-o-right" aria-hidden="true"></i>基本信息</legend>
            <div class="form-group">
                <label class="col-sm-2 col-md-1 control-label"><font color="red">所属公司：</font></label>
                <div class="col-sm-10 col-md-2">
                    <sys:treeselectNew id="company" name="company.id" value="${user.company.id}"
                                       labelName="reach.name" labelValue="${user.company.name}"
                                       title="公司" url="/sys/office/treeData?type=2" fullName="false" notAllowSelectParent="true"
                                       allowClear="true" cssClass="form-control "/>
                </div>

                <label class="col-sm-2 col-md-1 control-label"><font color="red">姓名：</font></label>
                <div class="col-sm-10 col-md-2">
                    <form:input path="name" htmlEscape="false" maxlength="50" class="form-control "/>
                </div>
                <label class="col-sm-2 col-md-1 control-label"><font color="red">登录名：</font></label>
                <div class="col-sm-10 col-md-2">
                    <input id="oldLoginName" name="oldLoginName" type="hidden" value="${user.loginName}">
                    <form:input path="loginName" htmlEscape="false" maxlength="50" class="form-control  userName"/>
                </div>
                <label class="col-sm-2 col-md-1 control-label">手机：</label>
                <div class="col-sm-10 col-md-2">
                    <form:input path="mobile" htmlEscape="false" maxlength="100" class="form-control"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 col-md-1 control-label">微信账号：</label>
                <div class="col-sm-10 col-md-2">
                    <form:input path="wxname" htmlEscape="false" maxlength="100" class="form-control "/>
                </div>
                <label class="col-sm-2 col-md-1 control-label"><c:if test="${empty user.id}"><font color="red">*</font></c:if>密码:</label>
                <div class="col-sm-10 col-md-2">
                    <input id="newPassword" name="newPassword" type="password" value="" maxlength="50" minlength="3"
                    class="form-control ${empty user.id?'':''}"/>
                    <c:if test="${not empty user.id}"><span class="help-inline">若不修改密码，请留空。</span></c:if>
                </div>
                <label class="col-sm-2 col-md-1 control-label"><c:if test="${empty user.id}"><font color="red">*</font></c:if>确认密码:</label>
                <div class="col-sm-10 col-md-2">
                    <input id="confirmNewPassword" name="confirmNewPassword" type="password"
                           class="form-control ${empty user.id?'':''}" value="" maxlength="50" minlength="3"
                           equalTo="#newPassword"/>
                </div>
            </div>
        </fieldset>
        <fieldset>
            <legend><i style="padding: 0px 5px 0px 5px" class="fa fa-hand-o-right" aria-hidden="true"></i>设置</legend>
            <div class="form-group">
                <label class="col-sm-2 col-md-1 control-label">是否宿主：</label>
                <div class="col-sm-10 col-md-2">
                    <select id="isOwn" name="isOwn" class="form-control" data-value="${user.isOwn}">
                        <option value=""></option>
                        <c:forEach items="${fns:getDictList('yes_no')}" var="dict">
                            <option value="${dict.value}">${dict.label}</option>
                        </c:forEach>
                    </select>
                </div>

                <label class="col-sm-2 col-md-1 control-label">查看首页：</label>
                <div class="col-sm-10 col-md-2">
                    <select id="isShouYe" name="isShouYe" class="form-control" data-value="${user.isShouYe}">
                        <option value=""></option>
                        <option value="1">查看待办</option>
                        <option value="2">查看全部</option>
                    </select>
                </div>
                <label class="col-sm-2 col-md-1 control-label">所属上级：</label>
                <div class="col-sm-10 col-md-2">
                    <sys:userselect id="isUser" name="isUser.id" value="${user.isUser.id}"
                                    labelName="isUser.name" labelValue="${user.isUser.name}"
                                    cssClass="form-control "/>
                </div>
                <%--<c:if test="${not empty user.id}">
                    <label class="col-sm-2 col-md-1 control-label">创建时间：</label>
                    <div class="col-sm-10 col-md-2">
                        <span class="lbl"><fmt:formatDate value="${user.createDate}" type="both" dateStyle="full"/></span>
                    </div>
                    <label class="col-sm-2 col-md-1 control-label">最后登陆：</label>
                    <div class="col-sm-10 col-md-2">
                        <span class="lbl">IP: ${user.loginIp}&nbsp;&nbsp;&nbsp;&nbsp;时间：<fmt:formatDate
                                value="${user.loginDate}" type="both" dateStyle="full"/></span>
                    </div>
                </c:if>--%>
            </div>
            <div class="form-group">
              <%--  <label class="col-sm-2 col-md-1 control-label">销售范围：</label>
                <div class="col-sm-10 col-md-11">
                    <sys:treeselectNew id="comIds" name="comIds.id" value="${user.comIds.id}"
                                       labelName="comIds.name" labelValue="${user.comIds.name}"
                                       title="公司" url="/sys/office/treeData?type=2" fullName="false" notAllowSelectParent="false" checked="true"
                                       allowClear="true" cssClass="form-control"/>
                </div>--%>
                <c:if test="${not empty user.id}">
                    <label class="col-sm-2 col-md-1 control-label">创建时间：</label>
                    <div class="col-sm-10 col-md-2">
                        <span class="lbl"><fmt:formatDate value="${user.createDate}" type="both" dateStyle="full"/></span>
                    </div>
                    <label class="col-sm-2 col-md-1 control-label">最后登陆：</label>
                    <div class="col-sm-10 col-md-2">
                        <span class="lbl">IP: ${user.loginIp}&nbsp;&nbsp;&nbsp;&nbsp;时间：<fmt:formatDate
                                value="${user.loginDate}" type="both" dateStyle="full"/></span>
                    </div>
                </c:if>
            </div>

        </fieldset>
        <fieldset>
            <legend><i style="padding: 0px 5px 0px 5px" class="fa fa-hand-o-right" aria-hidden="true"></i>角色权限</legend>
            <div class="form-group">
                <label class="col-sm-2 col-md-1 control-label">用户角色：</label>
                <div class="col-sm-10 col-md-2">
                    <form:checkboxes path="roleIdList" element="p" items="${allRoles}" itemLabel="name" itemValue="id"
                                     htmlEscape="false" cssClass="i-checks"/>
                    <label id="roleIdList-error" class="error" for="roleIdList"></label>
                </div>

</form:form>
</body>
</html>
